Skip to main content

Unix Interview Questions and Answers

 Basic Commands


  1. What is the command to list all files in a directory, including hidden files?

            ls -a

            The -a option lists all files, including hidden ones that start with a dot (.).


  1. How do you display the contents of a file?

cat filename

Other commands like more, less, head, and tail can also be used to display file contents.


  1. How do you copy a file from one location to another?

cp source_file destination_file


  1. How do you move or rename a file?

mv old_name new_name 

mv file_name /path/to/new_location/


  1. How do you remove a file and a directory?

rm file_name 

rm -r directory_name



File Permissions


  1. How do you change the permissions of a file?

chmod 755 filename

This sets the file permissions to rwxr-xr-x.


  1. How do you change the owner of a file?

chown new_owner filename


  1. How do you change the group ownership of a file?

chgrp new_group filename


  1. What does chmod 644 filename do?

It sets the file permissions to rw-r--r--, which means the owner can read and write, while the group and others can only read.



Process Management


  1.  How do you list currently running processes?

ps

Use ps aux for a more detailed view and top or htop for a dynamic view.


  1. How do you kill a process by its process ID (PID)?

kill PID

Use kill -9 PID to force kill a process.


  1. How do you bring a background process to the foreground?

fg


  1. How do you send a process to the background?

Bg

Use & at the end of a command to start it in the background:

command &



File Management


  1. How do you find files in a directory with a specific pattern?

find /path -name "*.txt"

This finds all .txt files in the specified path.


  1. How do you search for a specific text in files?

grep "text_to_search" filename

Use grep -r "text_to_search" /path to search recursively.


  1. How do you count the number of lines, words, and characters in a file?

wc filename

You can also use wc -l, wc -w, and wc -c for lines, words, and characters, respectively.


  1. How do you display the first and last 10 lines of a file?

head filename 

tail filename

Use head -n 20 filename and tail -n 20 filename to display the first and last 20 lines.



Scripting


  1. How do you create a simple shell script?

#!/bin/bash 

echo "Hello, World!"

Save the file and make it executable:

chmod +x script_name.sh 

./script_name.sh


  1. How do you set a variable in a shell script?

variable_name="value" 

echo $variable_name


  1. How do you read input from a user in a shell script?

read -p "Enter your name: " name 

echo "Hello, $name"


  1. How do you write an if statement in a shell script?

if [ $variable -eq 1 ]; then

echo "Variable is equal to 1"

Else

echo "Variable is not equal to 1"

fi



File Compression


  1. How do you compress files using gzip and tar?

gzip filename 

tar -czvf archive_name.tar.gz directory_name


  1. How do you extract compressed files?

gunzip filename.gz

tar -xzvf archive_name.tar.gz



Networking


  1. How do you display network interfaces and IP addresses?

Ifconfig

Use ip addr show for more modern systems.


  1. How do you test network connectivity?

ping hostname_or_ip


  1. How do you transfer files between systems using scp?

scp source_file user@remote_host:/path/to/destination



System Administration


  1. How do you check disk usage in Unix?

df -h


  1. How do you check memory usage?

free -m


  1. How do you change the hostname of a Unix system?

sudo hostname new_hostname


  1. How do you schedule a job using cron?

Edit the crontab file using crontab -e and add a line in the format:

* * * * * /path/to/command

The five asterisks represent the minute, hour, day of the month, month, and day of the week, respectively.



Comments

Popular posts from this blog

Autosys Interview Questions and Answers

1. What is Autosys? Autosys is a job scheduling and workload automation tool that allows users to define, schedule, monitor, and manage jobs. It automates repetitive tasks and ensures timely execution of jobs across various platforms. 2. What are the key components of Autosys? The key components of Autosys include: Event Server: Stores job definitions, schedules, and statuses. Event Processor: Processes job definitions and schedules jobs based on defined conditions. Remote Agent: Installed on target machines to execute jobs. Autosys GUI (Graphical User Interface) and CLI (Command Line Interface): Interfaces for job management and monitoring. 3. What are some common job types in Autosys? Common job types in Autosys include: Command Job: Executes a command or script on a specified machine. File Watcher Job: Monitors for the arrival, modification, or deletion of a file. Box Job: Container for grouping multiple jobs. Database Job: Executes SQL queries or stored procedures. Batch J...

ITIL Interview Questions and Answers

  What is ITIL? ITIL (Information Technology Infrastructure Library) is a framework of best practices for       IT service management (ITSM) that focuses on aligning IT services with the needs of the business. It provides guidance on delivering services that are efficient, effective, and of high quality. ITIL consists of a set of practices and processes that cover various stages of the service lifecycle, from strategy and design to operation and continual improvement. What are the main benefits of implementing ITIL in an organization?                         Implementing ITIL can bring several benefits to an organization, including: Improved alignment of IT services with business needs and goals. Enhanced service quality and consistency. Increased customer satisfaction through better service delivery. Greater efficiency and productivity within IT operati...